<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 固定资产管理系统</title>
    
    <!-- Bootstrap CSS -->
    {% load static %}
    <link href="{% static 'vendor/bootstrap/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'vendor/fontawesome/all.min.css' %}" rel="stylesheet">
    
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        .login-container {
            width: 100%;
            max-width: 400px;
            padding: 20px;
        }
        
        .login-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            backdrop-filter: blur(10px);
        }
        
        .login-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            text-align: center;
            padding: 30px 20px;
        }
        
        .system-logo {
            width: 60px;
            height: 60px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 15px;
            font-size: 1.8rem;
        }
        
        .system-title {
            font-size: 1.5rem;
            font-weight: 600;
            margin-bottom: 5px;
        }
        
        .system-subtitle {
            font-size: 0.9rem;
            opacity: 0.9;
        }
        
        .login-form {
            padding: 30px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-label {
            font-weight: 500;
            color: #333;
            margin-bottom: 8px;
            display: flex;
            align-items: center;
        }
        
        .form-control {
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            padding: 12px 15px;
            font-size: 1rem;
            transition: all 0.3s ease;
        }
        
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        
        .login-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 8px;
            padding: 12px;
            font-size: 1rem;
            font-weight: 500;
            color: white;
            width: 100%;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .login-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
        }
        
        .login-btn:disabled {
            opacity: 0.7;
            cursor: not-allowed;
            transform: none;
        }
        
        .loading-spinner {
            display: none;
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s linear infinite;
            margin-right: 8px;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        .remember-me {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .remember-me input {
            margin-right: 8px;
        }
        
        .remember-me label {
            font-size: 0.9rem;
            color: #666;
            cursor: pointer;
        }
        
        .alert {
            border-radius: 8px;
            margin-bottom: 20px;
        }
        
        .login-footer {
            text-align: center;
            padding: 15px;
            color: rgba(255, 255, 255, 0.8);
            font-size: 0.85rem;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .login-container {
                max-width: 90%;
                padding: 10px;
            }
            
            .login-form {
                padding: 20px;
            }
            
            .login-header {
                padding: 25px 15px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-card">
            <!-- 登录头部 -->
            <div class="login-header">
                <div class="system-logo">
                    <i class="fas fa-boxes"></i>
                </div>
                <h1 class="system-title">资产管理系统</h1>
                <p class="system-subtitle">固定资产全生命周期管理平台</p>
            </div>

            <!-- 登录表单 -->
            <div class="login-form">
                {% if messages %}
                    {% for message in messages %}
                        <div class="alert alert-{{ message.tags }} alert-dismissible fade show">
                            <i class="fas fa-exclamation-triangle me-2"></i>
                            {{ message }}
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                    {% endfor %}
                {% endif %}

                <form method="post" id="loginForm">
                    {% csrf_token %}
                    
                    <div class="form-group">
                        <label for="username" class="form-label">
                            <i class="fas fa-user me-2"></i>用户名
                        </label>
                        <input type="text" 
                               class="form-control" 
                               id="username" 
                               name="username" 
                               placeholder="请输入用户名"
                               required 
                               autocomplete="username"
                               value="{{ request.POST.username|default:'' }}">
                    </div>

                    <div class="form-group">
                        <label for="password" class="form-label">
                            <i class="fas fa-lock me-2"></i>密码
                        </label>
                        <input type="password" 
                               class="form-control" 
                               id="password" 
                               name="password" 
                               placeholder="请输入密码"
                               required 
                               autocomplete="current-password">
                    </div>

                    <div class="remember-me">
                        <input type="checkbox" id="remember" name="remember" class="form-check-input">
                        <label for="remember" class="form-check-label">记住我</label>
                    </div>

                    <button type="submit" class="login-btn" id="loginBtn">
                        <span class="loading-spinner" id="loadingSpinner"></span>
                        <span id="btnText">
                            <i class="fas fa-sign-in-alt me-2"></i>立即登录
                        </span>
                    </button>
                </form>
            </div>
        </div>

        <!-- 页脚 -->
        <div class="login-footer">
            <p>&copy; 2025 固定资产管理系统. 保留所有权利.</p>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- 简化的登录脚本 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const form = document.getElementById('loginForm');
            const loginBtn = document.getElementById('loginBtn');
            const loadingSpinner = document.getElementById('loadingSpinner');
            const btnText = document.getElementById('btnText');
            const usernameInput = document.getElementById('username');
            const passwordInput = document.getElementById('password');
            const rememberCheckbox = document.getElementById('remember');
            
            // 加载记住的用户名
            const savedUsername = localStorage.getItem('rememberedUsername');
            if (savedUsername) {
                usernameInput.value = savedUsername;
                rememberCheckbox.checked = true;
                passwordInput.focus();
            } else {
                usernameInput.focus();
            }
            
            // 表单提交处理
            form.addEventListener('submit', function(e) {
                // 基本验证
                if (!usernameInput.value.trim()) {
                    e.preventDefault();
                    alert('请输入用户名');
                    usernameInput.focus();
                    return;
                }
                
                if (!passwordInput.value.trim()) {
                    e.preventDefault();
                    alert('请输入密码');
                    passwordInput.focus();
                    return;
                }
                
                // 显示加载状态
                loginBtn.disabled = true;
                loadingSpinner.style.display = 'inline-block';
                btnText.innerHTML = '登录中...';
                
                // 保存用户名
                if (rememberCheckbox.checked) {
                    localStorage.setItem('rememberedUsername', usernameInput.value.trim());
                } else {
                    localStorage.removeItem('rememberedUsername');
                }
                
                // 设置超时恢复按钮状态（防止网络问题导致按钮一直禁用）
                setTimeout(function() {
                    if (loginBtn.disabled) {
                        loginBtn.disabled = false;
                        loadingSpinner.style.display = 'none';
                        btnText.innerHTML = '<i class="fas fa-sign-in-alt me-2"></i>立即登录';
                    }
                }, 10000); // 10秒后恢复
            });
            
            // Enter键快速登录
            document.addEventListener('keydown', function(e) {
                if (e.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
                    if (document.activeElement === usernameInput) {
                        passwordInput.focus();
                    } else if (document.activeElement === passwordInput) {
                        form.submit();
                    }
                }
            });
            
            // 输入框焦点效果
            [usernameInput, passwordInput].forEach(input => {
                input.addEventListener('focus', function() {
                    this.style.borderColor = '#667eea';
                });
                
                input.addEventListener('blur', function() {
                    this.style.borderColor = '#e1e5e9';
                });
            });
        });
    </script>
</body>
</html>